package thread.exercise;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-03-04
 * Time:20:47
 */
public class Exercise1 {
    public static void main(String[] args) {
        Thread thread1 = new Thread(new T1());
        Thread thread2 = new Thread(new T2());
        thread1.start();
        thread2.start();
    }
}
class T2 implements Runnable{
    int time = 1;
    @Override
    public void run() {
        while (true) {
            System.out.println("hi");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (++time == 5) break;
        }
    }
}
class T1 implements Runnable {
    int time = 1;
    @Override
    public void run() {
        while (true) {
            System.out.println("hello world");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (++time == 10) break;
        }
    }
}
